<?php
namespace core\lib;
use core\lib\conf;
class routes
{
	public $controller; //控制器
	public $action;		//方法
	public function __construct(){
		
		/*
		*1.隐藏index.php
		*2.获取URL 参数部分
		*3.返回对应控制器和操作
		*/

		//p($_SERVER);
		//根据PATH_INFO来确定controller和action路径
		if (isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] != '/') {
			$path = $_SERVER['PATH_INFO'];
			$patharr = explode('/',trim($path,'/'));
			//p($patharr);
			if (isset($patharr[0])) {
				$this->controller = $patharr[0];
			}
			unset($patharr[0]);  //销毁
			if (isset($patharr[1])) {
				$this->action = $patharr[1];
				unset($patharr[1]);
			}else{
				$this->action = conf::get('ACTION','route');
			}
			
			//url多余的部分转换成GET
			//id/1/str/2/test/3
			//GET变量名不能是数字或数字字符串
			$count = count($patharr) + 2;
			$i = 2;

			while ($i < $count) {
				if (isset($patharr[$i+1])&&!is_numeric($patharr[$i])) {
					$_GET[$patharr[$i]] = $patharr[$i+1];
				}
				
				$i = $i + 2;
			}
			//p($_GET);


		}else{
			$this->controller = conf::get('CONTROLLER','route');
			$this->action = conf::get('ACTION','route');
		}
	}
}